package demo1;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: xiaotutu
 * Date: 2024-05-31
 * Time: 15:12
 */
public class Test {

    public static final String[] SUITS = {"♥", "♠", "♦", "♣"};
    
    // 生成牌
    public static List<Card> buyCard() {
        List<Card> cards = new ArrayList<>();
        for (int i = 0; i < SUITS.length; i++) {
            for (int j = 1; j <= 13; j++) {
                Card card = new Card(j, SUITS[i]);
                cards.add(card);
            }
        }
        return cards;
    }
    //洗牌
    public static void shuffle(List<Card> cards) {
        Random random = new Random();
        for (int i = cards.size()-1; i > 0; i--) {
            int j = random.nextInt(i);
            // 交换牌
            Card tmp = cards.get(i);
            cards.set(i, cards.get(j));
            cards.set(j, tmp);
        }
    }
    public static void main(String[] args) {
        List<Card> cards = buyCard();
        System.out.println("洗牌前");
        System.out.println(cards);
        //洗牌后
        System.out.println("洗牌后");
        shuffle(cards);
        System.out.println(cards);
        // 摸牌
        // 每个人牌放在哪里
        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();
        List<Card> hand3 = new ArrayList<>();

        List<List<Card>> hand = new ArrayList<>();
        hand.add(hand1);
        hand.add(hand2);
        hand.add(hand3);
        // 3个人轮流拿5张牌
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                // 每次拿最上面的牌
                Card card = cards.remove(0);
                // 按顺序拿牌
                hand.get(j).add(card);
            }
        }
        System.out.println("第一个人的牌");
        System.out.println(hand1);
        System.out.println("第二个人的牌");
        System.out.println(hand2);
        System.out.println("第三个人的牌");
        System.out.println(hand3);
    }
}
